package com.xuwei.treeslidemenu;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JOptionPane;

public class Main extends JFrame implements ActionListener {

    private static final long serialVersionUID = -7434328456746170603L;

    private TreeSlideMenu treeMenu;

    public static void main(String[] args) {
        new Main();

    }

    public Main() {
        Menu[] menu = new Menu[6];
        for (int i = 0; i < menu.length; i++) {
            menu[i] = new Menu();
            menu[i].setName("主菜单" + (i + 1));
            menu[i].setBackgroundColor(Color.CYAN);
        }

        Menu[] s1 = new Menu[35];
        for (int i = 0; i < s1.length; i++) {
            s1[i] = new Menu();
            s1[i].setName("1-子菜单" + (i + 1));
            s1[i].setBackgroundColor(Color.ORANGE);
        }

        Menu[] s2 = new Menu[5];
        for (int i = 0; i < s2.length; i++) {
            s2[i] = new Menu();
            s2[i].setName("2-子菜单" + (i + 1));
            s2[i].setBackgroundColor(Color.GREEN);
        }

        s2[0].blurActionListener(this);

        Menu[] s3 = new Menu[15];
        for (int i = 0; i < s3.length; i++) {
            s3[i] = new Menu();
            s3[i].setName("3-子菜单" + (i + 1));
        }

        Menu[] s4 = new Menu[15];
        for (int i = 0; i < s4.length; i++) {
            s4[i] = new Menu();
            s4[i].setName("4-子菜单" + (i + 1));
        }

        Menu[] s5 = new Menu[45];
        for (int i = 0; i < s5.length; i++) {
            s5[i] = new Menu();
            s5[i].setName("5-子菜单" + (i + 1));
        }

        menu[0].setSubMenus(s1);
        menu[1].setSubMenus(s2);
        menu[2].setSubMenus(s3);
        menu[3].setSubMenus(s4);
        menu[4].setSubMenus(s5);

        menu[5].blurActionListener(this);

        treeMenu = new TreeSlideMenu(menu, 500, 30);
        // treeMenu.setSubMenuHeight(50);
        // treeMenu.setSubMenuWidth(500);

        this.add(treeMenu);
        this.setVisible(true);
        this.setSize(500, 600);
        // this.setResizable(false);
        this.setLocationRelativeTo(null);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if ("5".equals(e.getActionCommand())) {
            JOptionPane.showMessageDialog(null, "你好，这是主菜单6");

        } else {
            JOptionPane.showMessageDialog(null, e.getActionCommand());
        }

    }

}
